<?php

	$db = mysql_connect('localhost', 'root', '') or die('Not connecting db');
	mysql_select_db('messenger') or die('Not selected db');

	// работа с бд
	$token = 'GHJITUBIUyyu89s86fsd67f8s';

	mysql_close($db);

?><!DOCTYPE html>
<html lang="ru">
<head>
	<meta charset="UTF-8">
	<title>Чат</title>
	<link rel="stylesheet" href="/maket_css/styles.css">
	<script type="text/javascript" src="jquery.js"></script>
	<script type="text/javascript">
			(function(){

				$.fn.Messenger = function(opts){
					
					var _this = $(this);
					var token = opts.token;
					var contacts = {};
					var contact_list = _this.find('#contact_list');
					var contacts_online = {};

					// API
					var get_contact_list = function(){
						$.ajax({
							url: 'http://messenger/app/services.php',
							method: 'post',
							dataType: 'json',
							data: { __module: 'messenger', __action: 'get_contact_list' },
							success: function(data) {
								if(data.result === 'ok'){
									contacts = data.data;
									refresh_contacts();
								}
							}
						});
					};
					var add_user_contact_list = function(){};
					var remove_user_contact_list = function(){};
					var send_messege = function(){};
					var show_all_contacts = function(){};
					var show_last_contacts = function(){};
					var get_list_contact_online = function(){
						$.ajax({
							url: 'http://messenger/app/services.php',
							method: 'post',
							dataType: 'json',
							data: { __module: 'messenger', __action: 'get_list_contact_online' },
							success: function(data) {
								if(data.result === 'ok'){
									contacts = data.data;
									refresh_contacts();
								}
							}
						});	
					};
					var check_new_message = function(){};
					var show_last_message = function(){};
					var show_all_message = function(){};
					var search_contact = function(){};


					// actions
					var refresh_contacts = function() {
						contact_list.html('');
						$.each(contacts, function(i){
							var html = '';
							if(contacts[i].status){
								html = '<li><a rel="' + contacts[i].id + '" href="#">' + contacts[i].name + '<span class="counter">online</span></a></li>';
							} else {
								html = '<li><a rel="' + contacts[i].id + '" href="#">' + contacts[i].name + '</a></li>';
							}
							contact_list.append(html);
						});
					}

					var init = function(){
						get_contact_list();

					};

					init();
					// binds


				}

			})();

			$(document).ready(function(){
				$('#messenger').Messenger({ token : '<?php print $token; ?>' });
			});
	</script>
</head>
<body>
	<div class="rows">
		<div class="w25">
			<?php include($_SERVER['DOCUMENT_ROOT'] . '/maket_css/contacts.html'); ?>
		</div>
		<div class="w75">
			<?php include($_SERVER['DOCUMENT_ROOT'] . '/maket_css/chat.html'); ?>
		</div>
	</div>
</body>
</html>